<?php

namespace App\Http\Requests\airline\base;

use App\Http\ValidateResult;
use Illuminate\Support\Facades\Validator;

trait FlightRequest
{
    public static function add_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'company_id' => 'required|integer',
            'flight_number' => 'required',
//            'start_port_id' => 'required|integer',
//            'arrive_port_id' => 'required|integer',
            'route_id' => 'required',
            'take_off_time' => 'required',
            'landing_time' => 'required',
            'classes' => 'required',
        ], [
            'company_id.required' => '请选择航空公司',
            'code.required' => '请填写航班号',
//            'start_port_id.required' => '请选择出发机场',
//            'arrive_port_id.required' => '请选择到达机场',
            'route_id.required' => '请选择航线',
            'take_off_time.required' => '请填写起飞时间',
            'landing_time.required' => '请填写降落时间',
            'classes.required' => '请填写航班班次',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

}
